package com.yanchangapp.ui.presenter;

import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.response.WorkItemDetailResponse;
import com.yanchangapp.ui.view.WorkItemDtAtView;
import com.zxl.baselib.bean.response.BaseResponse;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019-10-10.
 * description: 我的工作项p层
 */
public class WorkItemDtAtPresenter extends BasePresenter<WorkItemDtAtView> {

    public WorkItemDtAtPresenter(BaseActivity context) {
        super(context);
    }


    public void queryWorkItemDetail(long workItemID){
        HeadApiRetrofit.getInstance().getQueryWorkItemDetail(workItemID)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<WorkItemDetailResponse>>() {
                    @Override
                    public void onNext(BaseResponse<WorkItemDetailResponse> workItemDetailResponseBaseResponse) {
                        if (getView() != null){
                            if (workItemDetailResponseBaseResponse.getCode() ==
                                    AppConstant.REQUEST_SUCCESS){
                                getView().queryWorkItemDetailSuccess(workItemDetailResponseBaseResponse.getData());
                            }else {
                                getView().queryWorkItemDetailFailure(workItemDetailResponseBaseResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (getView() != null){
                            getView().queryWorkItemDetailFailure("网络错误");
                        }
                    }
                });
    }
}
